<template>
  <el-dialog title="批量核算审批" width="30%" :visible.sync="visible">
    <el-form ref="form" :model="form" class="dialog-form" label-position="right" label-width="120px">
      <el-form-item label="审批笔数：">
        <label>{{ orderCount }}</label>
      </el-form-item>
      <el-form-item v-if="totalActualAmount" label="核算金额：">
        <label>￥<span class="money">{{ totalActualAmount.toFixed(2) }}</span></label>
      </el-form-item>
      <el-form-item label="标记类型：">
        <el-radio-group v-model="form.flag" @change="flagChange">
          <el-radio :label="0" name="哈哈">正常付款</el-radio>
          <el-radio :label="3">暂不付款</el-radio>
          <el-radio :label="4">急需付款</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="补充描述：" prop="message" :rules="$ruleStore.rules.def">
        <el-input v-model="form.message" type="textarea" :rows="2" placeholder="请输入补充描述" />
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button size="mini" @click="visible = false">取 消</el-button>
      <el-button size="mini" type="primary" @click="submit">提交</el-button>
    </div>
  </el-dialog>
</template>
<script>
export default {
  name: 'PurBacthReplying',
  props: {
    parent: {
      type: Object,
      default: null
    }
  },
  data() {
    return {
      visible: false,
      form: {
        id: 0,
        flag: 0,
        message: '',
        params: { actualAmount: 0 }
      },
      totalActualAmount: 0,
      orderCount: 0
    }
  },
  created() {
  },
  mounted() {
  },
  methods: {
    show(supplierId, totalActualAmount, ids, actualAmounts) {
      this.visible = true
      this.totalActualAmount = totalActualAmount
      this.orderCount = ids.length
      this.form.params.ids = ids
      this.form.params.actualAmounts = actualAmounts
      this.form.params.totalActualAmount = totalActualAmount
    },
    flagChange(flag) {
      let flagName = ''
      switch (flag) {
        case 3:
          flagName = '暂不付款,付款时间：'
          break
        case 4:
          flagName = '急需付款,付款时间：'
          break
        default:
          flagName = ''
          break
      }
      this.form.message = flagName
    },
    submit() {
      const that = this
      that.$refs['form'].validate((valid) => {
        if (!valid) {
          return
        }
        const loading = that.$loading()
        const url = that.$http.conf.api.get('wms').url + '/api/pur/order-info/batch/replying'
        that.$http.post(url, that.form).then(res => {
          loading.close()
          if (res.code !== 200) {
            that.$message.error(res.message)
            return
          }
          that.$message.success('操作成功!')
          that.parent.search()
          that.visible = false
        }).catch((e) => {
          loading.close()
        })
      })
    }
  }
}
</script>
